package com.example.usermanagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/hello")
    public String hello() {
        return "Hello World!";
    }

    @GetMapping("/checkConnection")
    public String checkConnection() {
        try {
            String sql = "SELECT 1 FROM dual";  // Oracle 的 dual 表是一个虚拟表
            jdbcTemplate.queryForObject(sql, Integer.class);
            return "Connection to Oracle is successful!";
        } catch (Exception e) {
            return "Failed to connect to Oracle: " + e.getMessage();
        }
    }
}
